package com.gl.battleship.domain;

import java.util.ArrayList;
import java.util.List;

public class Ship {

	private ShipState stateShip;

	private List<Position> positions = new ArrayList<Position>();

	public Ship(ShipState stateShip) {
		this.stateShip = stateShip;
	}

	public void addPosition(Position position) {
		this.positions.add(position);
	}

	public ShipState getStateShip() {
		return stateShip;
	}

	public void setStateShip(ShipState stateShip) {
		this.stateShip = stateShip;
	}

	public List<Position> getPositions() {
		return positions;
	}

	public void setPositions(List<Position> positions) {
		this.positions = positions;
	}

	public void resfreshShip() {

		ShipState shipState = ShipState.NO_SUNK;

		for (Position position : positions) {
			if (position.getStatePosition() == StatePosition.HIT) {
				shipState = ShipState.HIT;
			}
		}

		if (shipState == ShipState.HIT) {

			shipState = ShipState.SUNK;

			for (Position position : positions) {
				if (position.getStatePosition() == StatePosition.NO_HIT) {
					shipState = ShipState.HIT;
				}
			}

		}
		this.setStateShip(shipState);
		return;
	}

}
